(function(e, i, n, o) {
    e.fn.extend({
        scrollspy: function(n) {
            var o = {
                min: 0,
                max: 0,
                mode: "vertical",
                buffer: 0,
                container: i,
                onEnter: n.onEnter ? n.onEnter: [],
                onLeave: n.onLeave ? n.onLeave: [],
                onTick: n.onTick ? n.onTick: []
            };
            var n = e.extend({},
            o, n);
            return this.each(function(i) {
                var o = this;
                var r = n;
                var t = e(r.container);
                var a = r.mode;
                var s = r.buffer;
                var l = leaves = 0;
                var c = false;
                t.bind("scroll.scrollspy",
                function(i) {
                    var n = {
                        top: e(this).scrollTop(),
                        left: e(this).scrollLeft()
                    };
                    var v = a == "vertical" ? n.top + s: n.left + s;
                    var f = r.max;
                    var u = r.min;
                    if (e.isFunction(r.max)) {
                        f = r.max()
                    }
                    if (e.isFunction(r.min)) {
                        u = r.min()
                    }
                    if (f == 0) {
                        f = a == "vertical" ? t.height() : t.outerWidth() + e(o).outerWidth()
                    }
                    if (v >= u && v <= f) {
                        if (!c) {
                            c = true;
                            l++;
                            e(o).trigger("scrollEnter", {
                                position: n
                            });
                            if (e.isFunction(r.onEnter)) {
                                r.onEnter(o, n)
                            }
                        }
                        e(o).trigger("scrollTick", {
                            position: n,
                            inside: c,
                            enters: l,
                            leaves: leaves
                        });
                        if (e.isFunction(r.onTick)) {
                            r.onTick(o, n, c, l, leaves)
                        }
                    } else {
                        if (c) {
                            c = false;
                            leaves++;
                            e(o).trigger("scrollLeave", {
                                position: n,
                                leaves: leaves
                            });
                            if (e.isFunction(r.onLeave)) {
                                r.onLeave(o, n)
                            }
                        }
                    }
                })
            })
        }
    })
})(jQuery, window); (function() {
    "use strict";
    if (typeof Eleme === "undefined") {
        window.Eleme = {}
    }
    var t = Eleme.Common.Evt;
    function e(t) {
        this.values = t || {};
        this.events = {};
        this.init()
    }
    $.extend(e.prototype, t);
    e.prototype.init = function() {
        this.setDefaults()
    };
    e.prototype.setDefaults = function() {
        _.defaults(this.values, {
            favored: false,
            distance: "",
            deliver_amount: 0
        })
    };
    e.prototype.favor = function() {
        this.sync("favor", {},
        this.favorHandler,
        function() {})
    };
    e.prototype.unFavor = function() {
        this.sync("unfavor", {},
        this.unFavorHandler,
        function() {})
    };
    e.prototype.favorHandler = function() {
        this.values.favored = true;
        this.trigger("favorStateChange")
    };
    e.prototype.unFavorHandler = function() {
        this.values.favored = false;
        this.trigger("favorStateChange")
    };
    e.prototype.sync = function(t, e, o, n) {
        var a, r, i = this,
        s = {
            favor: {
                url: window.location.pathname + "/favor",
                type: "post"
            },
            unfavor: {
                url: window.location.pathname + "/unfavor",
                type: "post"
            }
        };
        r = s[t].type;
        a = ELEME.baseUrl + s[t].url;
        $.ajax({
            type: r,
            url: a,
            success: function(t, e, n) {
                o.call(i, t, e, n)
            },
            error: function(t, e, o) {
                n.call(i, t, e, o)
            }
        })
    }; ! Eleme.Model && (Eleme.Model = {});
    Eleme.Model.Restaurant = e
})(); (function() {
    "use strict";
    var e = Eleme.Common.PubSub;
    var t = {
        basketSyncSuccessTopic: "basketSyncSuccess",
        basketSyncErrorTopic: "baksetSyncError"
    };
    function s(e) {
        this.values = e;
        this.init()
    }
    s.prototype.init = function() {
        this.setDefaults()
    };
    s.prototype.setDefaults = function() {
        _.defaults(this.values, {
            isGarnish: false,
            award: []
        })
    };
    s.prototype.sync = function(s, o) {
        var a = {
            increase: {
                url: "/cart/add",
                type: "get"
            },
            decrease: {
                url: "/cart/decrease",
                type: "get"
            },
            remove: {
                url: "/cart/delete",
                type: "get"
            },
            set: {
                url: "/cart/set",
                type: "get"
            }
        },
        r = "http://" + ELEME.mainHost + a[s].url + o.url,
        i = o.option,
        n = a[s].type;
        if (!r) {
            throw new Error("invalid sync method")
        }
        $.ajax({
            type: n,
            url: r,
            data: o.payload,
            dataType: "jsonp",
            success: function(s) {
                e.publish(t.basketSyncSuccessTopic, s, i)
            },
            error: function(s) {
                e.publish(t.basketSyncErrorTopic, s)
            }
        })
    };
    s.prototype.increase = function(e) {
        var t = this.values.parentFoodId || 0;
        this.sync("increase", {
            url: "/" + this.values.groupId + "/" + t + "/" + this.values.id,
            payload: {
                num: 1
            },
            option: e
        })
    };
    s.prototype.decrease = function(e) {
        var t = this.values.parentFoodId || 0;
        this.sync("decrease", {
            url: "/" + this.values.groupId + "/" + t + "/" + this.values.id,
            payload: {
                num: -1
            },
            option: e
        })
    };
    s.prototype.remove = function(e) {
        var t = this.values.parentFoodId || 0;
        this.sync("remove", {
            url: "/" + this.values.groupId + "/" + t + "/" + this.values.id,
            option: e
        })
    };
    s.prototype.set = function(e, t) {
        var s = this.values.parentFoodId || 0;
        this.sync("set", {
            url: "/" + this.values.groupId + "/" + s + "/" + this.values.id,
            payload: {
                num: e
            },
            option: t
        })
    }; ! Eleme.Model && (Eleme.Model = {});
    Eleme.Model.BasketFood = s
})(); (function() {
    "use strict";
    if (typeof Eleme === "undefined") {
        window.Eleme = {}
    }
    var e = Eleme.Common.PubSub,
    t = Eleme.Common.TemplateCache;
    var o = {
        tplSelector: "#basket-food-tpl",
        increaseBtnSelector: ".i_btn",
        decreaseBtnSelector: ".d_btn",
        numInputSelector: ".set_num_in",
        removeBtnSelector: ".r_btn",
        elemTag: "<li>",
        className: "rcart-dish"
    };
    function i(e, t) {
        this.$el = null;
        this.food = e;
        this.init(t)
    }
    i.prototype.init = function() {
        this.$el = $(o.elemTag).addClass(o.className);
        this.bindEvents()
    };
    i.prototype.render = function() {
        var e = t.get(o.tplSelector);
        this.$el.html(e($.extend({},
        this.food.values)));
        return this
    };
    i.prototype.remove = function() {
        var t = this.$el.find(o.removeBtnSelector);
        if (t.hasClass("loading")) {
            return
        }
        t.addClass("loading");
        e.subscribeOnce(o.basketSyncSuccessTopic,
        function() {
            var e = this.$el.find(o.removeBtnSelector);
            e.removeClass("loading")
        },
        this);
        this.food.remove({
            basket: true
        })
    };
    i.prototype.increase = function() {
        this.food.increase({
            basket: true
        })
    };
    i.prototype.decrease = function() {
        this.food.decrease({
            basket: true
        })
    };
    i.prototype.clear = function() {
        this.$el.off();
        this.$el.remove()
    };
    i.prototype.set = function() {
        var e = this.$el.find(o.numInputSelector),
        t = window.parseInt(e.val(), 10);
        this.food.set(t, {
            basket: true
        })
    };
    i.prototype.bindEvents = function() {
        this.$el.on("click", o.increaseBtnSelector, $.proxy(this.increase, this));
        this.$el.on("click", o.decreaseBtnSelector, $.proxy(this.decrease, this));
        this.$el.on("click", o.removeBtnSelector, $.proxy(this.remove, this));
        this.$el.on("change", o.numInputSelector, $.proxy(this.set, this))
    };
    i.prototype.toggleView = function() {
        this.$el.toggle()
    }; ! Eleme.View && (Eleme.View = {});
    Eleme.View.BasketFoodView = i
})(); (function(t) {
    t = t || {};
    var e = t.Common.Evt,
    a = t.Common.PubSub;
    var o = {
        foodAddTopic: "addFoodToBasket",
        basketSyncSuccessTopic: "basketSyncSuccess",
        bookStateChangeTopic: "bookStateChange",
        basketStateChangeTopic: "basketStateChange",
        favorFoodUpdateTopic: "favorFoodUpdate",
        invalidBasketCode: 1002
    };
    function i(t, e) {
        this.values = t;
        this.events = {};
        this.init(e)
    }
    $.extend(i.prototype, e);
    i.prototype.init = function() {
        this.buildSearchIndex();
        this.setDefaults();
        this.values.star = Math.round(this.values.rating * 2);
        if (this.values.img !== "") {
            this.values.isImgFood = true
        }
    };
    i.prototype.buildSearchIndex = function() {
        this.values.searchIndex = this.values.name;
        if (this.values.pinyinName) {
            this.values.searchIndex += this.values.pinyinName
        }
    };
    i.prototype.setDefaults = function() {
        _.defaults(this.values, {
            basket: {},
            stock: 0,
            inBasket: 0,
            attributes: [],
            description: "",
            rating: 0,
            commentNum: 0,
            salesNum: 0,
            price: 0,
            originPrice: 0,
            isFavor: false,
            isImgFood: false,
            activityImages: [],
            img: ""
        });
        this.values.activityImages = this.values.activityImages.slice(0, 1)
    };
    i.prototype.favor = function() {
        var t, e, a = {
            foodId: this.values.id
        };
        if (this.values.isFavor) {
            t = "unfavor";
            a = {
                url: "/" + this.values.id + "/unfavor"
            };
            e = this.unFavorHandler
        } else {
            t = "favor";
            a = {
                url: "/" + this.values.id + "/favor"
            };
            e = this.favorHandler
        }
        this.sync(t, a, e)
    };
    i.prototype.sync = function(t, e, a, o) {
        var i = this,
        s = {
            favor: {
                url: "/food" + e.url,
                type: "get"
            },
            unfavor: {
                url: "/food" + e.url,
                type: "get"
            },
            add: {
                url: "/cart/add" + e.url,
                type: "get"
            }
        },
        r = "http://" + ELEME.mainHost + s[t].url,
        n = s[t].type;
        if (!r) {
            throw new Error("invalid food sync")
        }
        $.ajax({
            type: n,
            url: r,
            data: e.payload,
            dataType: "jsonp"
        }).done(function(t, e, o) {
            a.call(i, t, e, o)
        }).fail(function(t) {
            o.call(i, t.responseJSON)
        })
    };
    i.prototype.addToBasket = function(t) {
        t = t || {};
        var e = {
            num: 1
        },
        a = t.basketId || 0,
        o = t.mainFoodId || 0;
        if (t.force) {
            e.forced = 1
        }
        if (!this.values.basket[a]) {
            this.values.basket[a] = 0
        }
        this.sync("add", {
            url: "/" + a + "/" + o + "/" + this.values.id,
            payload: e
        },
        this.addToBasketHandler, this.addFoodFailureHandler)
    };
    i.prototype.addFoodFailureHandler = function(t) {
        if (t && t.code === o.invalidBasketCode) {
            this.trigger("invalidBasket")
        }
    };
    i.prototype.addToBasketHandler = function(t) {
        a.publish(o.basketSyncSuccessTopic, t)
    };
    i.prototype.favorHandler = function(t) {
        if (t === 0) {
            return
        } else if (t === 1) {
            this.values.isFavor = true;
            this.trigger("favorStateChange.commentFood");
            this.trigger("favorStateChange.food");
            a.publish(o.favorFoodUpdateTopic, this, {
                favor: true
            })
        }
    };
    i.prototype.unFavorHandler = function(t) {
        if (t === 0) {
            return
        } else if (t === 1) {
            this.values.isFavor = false;
            this.trigger("favorStateChange.commentFood");
            this.trigger("favorStateChange.food");
            a.publish(o.favorFoodUpdateTopic, this, {
                favor: false
            })
        }
    }; ! t.Model && (t.Model = {});
    t.Model.Food = i
})(Eleme); (function() {
    "use strict";
    if (typeof Eleme === "undefined") {
        window.Eleme = {}
    }
    var e = Eleme.Common.PubSub;
    var t = {
        basketSyncSuccessTopic: "basketSyncSuccess",
        basketSyncFailureTopic: "basketSyncError"
    };
    function s(e) {
        this.values = e;
        this.init()
    }
    s.prototype.init = function() {
        this.setDefault()
    };
    s.prototype.setDefault = function() {
        _.defaults(this.values, {
            foods: []
        })
    };
    s.prototype.clear = function() {
        var s = "http://" + ELEME.mainHost + "/cart/clear/" + this.values.id;
        $.ajax({
            type: "get",
            url: s,
            dataType: "jsonp"
        }).done(function(s) {
            e.publish(t.basketSyncSuccessTopic, s, {
                basket: true
            })
        }).fail(function(s) {
            var i = s.responseJSON;
            e.publish(t.basketSyncFailureTopic, i, {
                basket: true
            })
        })
    }; ! Eleme.Model && (Eleme.Model = {});
    Eleme.Model.Basket = s
})(); (function(t) {
    "use strict";
    if (typeof t === "undefined") {
        window.Eleme = {}
    }
    function e(t, e) {
        this.values = t;
        this.init(e)
    }
    e.prototype.init = function() {
        this.setDefaults();
        this.values.star = Math.round(this.values.rating * 2)
    };
    e.prototype.setDefaults = function() {
        _.defaults(this.values, {
            id: _.uniqueId("comment"),
            rating_text: "",
            rating: 0,
            image: ""
        })
    }; ! t.Model && (t.Model = {});
    t.Model.Comment = e
})(Eleme); (function() {
    "use strict";
    if (typeof Eleme === "undefined") {
        window.Eleme = {}
    }
    var e = Eleme.Model.Food;
    var t = {
        foodImg: ""
    };
    function o(e, t) {
        this.values = e;
        this.events = {};
        this.init(t)
    }
    $.extend(o.prototype, e.prototype);
    o.prototype.init = function() {
        this.setDefaults()
    };
    o.prototype.setDefaults = function() {
        _.defaults(this.values, {
            isFavor: false,
            foodImg: t.foodImg,
            description: "",
            totalComments: 0
        })
    }; ! Eleme.Model && (Eleme.Model = {});
    Eleme.Model.CommentFood = o
})(); (function() {
    "use strict";
    if (typeof Eleme === "undefined") {
        window.Eleme = {}
    }
    var e = Eleme.Common.Evt,
    t = Eleme.Common.PubSub,
    o = Eleme.Common.TemplateCache;
    var a = {
        nameSelector: ".food_name",
        addBtnSelector: ".add_btn",
        addMainBtnSelector: ".add_main_btn",
        mainFoodSelector: ".main-food",
        singleMainFoodSelector: ".single_main_food",
        bookBtnSelector: ".favor_btn",
        menuSelector: ".main_food_panel",
        btnsSelector: ".act_btns",
        cartTipSelector: "#clear_cart_panel",
        clearCartSelector: "#clear_cart",
        cancelClearCartSelector: "#cancel_clear_cart",
        basketStateSelector: ".dish_state",
        imgSelector: ".food_img",
        commentBlockSelector: ".cmt_block",
        addFoodTopic: "addFoodToBasket",
        showMainFoodTopic: "showMainFood",
        showCommentTopic: "showSlide",
        getBasketInfoTopic: "getBasketInfo",
        mainFoodMenuTpl: '<div class="rst-d-act-dropdown main_food_panel"><span class="helper">添加到以下菜品中</span></div>',
        mainFoodsTpl: "#main-food-tpl",
        clearCartPanelTpl: "#clear-basket-panel-tpl",
        tplSelector: "#rst-dish-tpl",
        tagName: "li",
        elemClassName: "rst-dish-item",
        imgElemClassName: "rst-dish-img-item",
        bookStateClass: "ui_favored"
    };
    function s(e, t) {
        this.id = "view" + Eleme.View.uuid++;
        this.element = null;
        this.food = e;
        this.events = {};
        this.buffer = null;
        this.init(t)
    }
    $.extend(s.prototype, e);
    s.prototype.init = function() {
        this.listenTo(this.food, "basketStateChange", $.proxy(this.basketStateHandler, this));
        this.listenTo(this.food, "favorStateChange.food", $.proxy(this.favorStateHandler, this));
        this.listenTo(this.food, "invalidBasket", $.proxy(this.showClearCartPanel, this));
        Eleme.View.views[this.id] = this;
        this.bindEvents()
    };
    s.prototype.$el = function() {
        if (!this.element) {
            this.element = $("#" + this.id)
        }
        return this.element
    };
    s.prototype.remove$el = function() {
        if (this.element) {
            this.element = null
        }
    };
    s.prototype.bindEvents = function() {
        this.click = this.handleClick
    };
    s.prototype.handleClick = function(e) {
        var o, s, i, n, r, l = this.$el(),
        d = $(e.target);
        if (d.hasClass(a.addBtnSelector.substr(1))) {
            r = t.publish(a.getBasketInfoTopic);
            if (r.restaurantId && r.restaurantId !== ELEME.restaurantId) {
                this.showClearCartPanel(r);
                e.stopPropagation();
                return
            }
            this.addToBasket()
        } else if (d.hasClass(a.addMainBtnSelector.substr(1))) {
            r = t.publish(a.getBasketInfoTopic, ELEME.restaurantId);
            if (r.restaurantId && r.restaurantId !== ELEME.restaurantId) {
                this.showClearCartPanel(r);
                e.stopPropagation();
                return
            }
            n = l.find(a.menuSelector);
            if (n.size() === 0) {
                this.clearMenu();
                t.publish(a.showMainFoodTopic, $.proxy(this.showMainFoodPanel, this));
                e.stopPropagation();
                return
            }
            if (n.parent().hasClass("ui_open")) {
                n.parent().removeClass("ui_open");
                n.remove()
            }
        } else if (d.hasClass(a.bookBtnSelector.substr(1))) {
            this.bookFood()
        } else if (d.hasClass(a.singleMainFoodSelector.substr(1))) {
            i = d.data("foodid");
            this.addToMainFood(i);
            this.clearMenu()
        } else if (d.attr("id") === a.clearCartSelector.substr(1)) {
            this.addToBasket({
                force: true
            });
            this.clearCartTipMenu()
        } else if (d.attr("id") === a.cancelClearCartSelector.substr(1)) {
            this.clearCartTipMenu()
        } else if (d.hasClass(a.nameSelector.substr(1)) || d.hasClass(a.commentBlockSelector.substr(1)) || l.find(a.imgSelector)[0] && $.contains(l.find(a.imgSelector)[0], e.target) || l.find(a.commentBlockSelector)[0] && $.contains(l.find(a.commentBlockSelector)[0], e.target)) {
            this.showComment()
        } else {
            o = $(a.menuSelector);
            s = o.parent(".rst-d-act");
            s.removeClass("ui_open");
            o.remove();
            o = $(a.cartTipSelector);
            if (o.length > 0) {
                o.remove()
            }
        }
    };
    s.prototype.showMainFoodPanel = function(e, t) {
        var s = o.get(a.mainFoodsTpl),
        i = $(a.mainFoodMenuTpl);
        i.append(s({
            mainFoods: t
        }));
        this.$el().find(a.addMainBtnSelector).parent().append(i).addClass("ui_open")
    };
    s.prototype.addToMainFood = function(e) {
        this.addToBasket({
            mainFoodId: e
        });
        this.$el().find(a.mainFoodSelector).hide()
    };
    s.prototype.render = function(e) {
        var t = this.food.values,
        s = o.get(a.tplSelector);
        t.img = ELEME.fussHost + this.makeImgSrc();
        this.buffer = e;
        e.begin(a.tagName);
        this.addPropertyToBuffer(e);
        e.pushOpenTag();
        e.push(s(t));
        e.pushCloseTag();
        return this
    };
    s.prototype.addPropertyToBuffer = function(e) {
        var t = this.food.values.isImgFood ? a.imgElemClassName: a.elemClassName;
        e.setId(this.id);
        e.setClass(t + " food_view")
    };
    s.prototype.destroy = function() {
        this.stopListening(this.food);
        this.$el().off().remove()
    };
    s.prototype.makeImgSrc = function() {
        var e, t, o = ".",
        a = "_size_240_180";
        if (!this.food.values.originImg) {
            this.food.values.originImg = this.food.values.img
        }
        t = this.food.values.originImg.split(".");
        e = t.pop();
        t.push(a, o, e);
        return t.join("")
    };
    s.prototype.showComment = function() {
        t.publish(a.showCommentTopic, this.food)
    };
    s.prototype.bookFood = function() {
        if (ELEME.authed) {
            this.food.favor()
        } else {
            window.location.href = ELEME.formerBaseUrl + "/login"
        }
    };
    s.prototype.addToBasket = function(e) {
        var o = this.$el().find(a.basketStateSelector);
        o.html("").removeClass("hide").addClass("loading");
        t.publish(a.addFoodTopic, $.proxy(this.food.addToBasket, this.food), e);
        t.publish("addFoodToBasketAnim", this)
    };
    s.prototype.showClearCartPanel = function(e) {
        var t = o.get(a.clearCartPanelTpl),
        s = this.$el().find(a.btnsSelector),
        i = this.$el().find(a.basketStateSelector),
        n = s.find(a.cartTipSelector);
        e = e || {};
        i.addClass("hide").removeClass("loading");
        if (n.size() > 0) {
            return
        }
        $(document).find(a.cartTipSelector).remove();
        e.foodName = this.food.values.name;
        e.restaurantName = e.restaurantName || "其他餐厅";
        s.append(t(e))
    };
    s.prototype.favorStateHandler = function() {
        var e = this.$el().find(a.bookBtnSelector);
        if (this.food.values.isFavor) {
            e.addClass(a.bookStateClass)
        } else {
            e.removeClass(a.bookStateClass)
        }
    };
    s.prototype.basketStateHandler = function() {
        var e = this.$el().find(a.basketStateSelector);
        e.removeClass("loading").html(this.food.values.inBasket);
        if (this.food.values.inBasket === 0) {
            e.addClass("hide")
        } else {
            e.removeClass("hide")
        }
    };
    s.prototype.scrollToView = function() {
        var e = this.$el().offset().top;
        $("html, body").animate({
            scrollTop: e - 45 + "px"
        })
    };
    s.prototype.clearMenu = function() {
        var e = $(a.menuSelector),
        t = e.parent(a.btnsSelector);
        if (!t.hasClass("ui_open")) {
            return
        }
        t.removeClass("ui_open");
        e.remove()
    };
    s.prototype.clearCartTipMenu = function() {
        this.$el().find(a.cartTipSelector).remove()
    }; ! Eleme.View && (Eleme.View = {});
    Eleme.View.FoodView = s
})(); (function() {
    "use strict";
    if (typeof Eleme === "undefined") {
        window.Eleme = {}
    }
    var e = Eleme.View.FoodView,
    t = Eleme.Common.TemplateCache;
    var i = {
        addBtnSelector: ".add_btn",
        foodNameSelector: ".food_name",
        addMainBtnSelector: ".add_main_btn",
        tplSelector: "#recommend-food-tpl",
        tagName: "li",
        className: "rst-aside-dish-item"
    };
    function o(e) {
        this.id = "view" + Eleme.View.uuid++;
        this.food = e;
        this.init()
    }
    $.extend(o.prototype, e.prototype);
    o.prototype.init = function() {
        Eleme.View.views[this.id] = this;
        this.bindEvents()
    };
    o.prototype.render = function(e) {
        var o = t.get(i.tplSelector);
        e.begin(i.tagName);
        e.setId(this.id).setClass(i.className + " food_view");
        e.pushOpenTag();
        e.push(o($.extend({},
        this.food.values)));
        e.pushCloseTag();
        return this
    }; ! Eleme.View && (Eleme.View = {});
    Eleme.View.RecommendFoodView = o
})(); (function() {
    "use strict";
    if (typeof Eleme === "undefined") {
        window.Eleme = {}
    }
    var e = Eleme.Common.TemplateCache,
    i = Eleme.View.FoodView;
    var o = {
        favorFoodTpl: "#favor-food-tpl",
        tagName: "li",
        className: "rst-aside-dish-item"
    };
    function t(e) {
        this.id = "view" + Eleme.View.uuid++;
        this.food = e;
        this.init()
    }
    $.extend(t.prototype, i.prototype);
    t.prototype.init = function() {
        Eleme.View.views[this.id] = this;
        this.bindEvents()
    };
    t.prototype.render = function(i) {
        var t = e.get(o.favorFoodTpl);
        i.begin(o.tagName);
        i.setId(this.id).setClass(o.className + " food_view");
        i.pushOpenTag();
        i.push(t(this.food.values));
        i.pushCloseTag()
    }; ! Eleme.View && (Eleme.View = {});
    Eleme.View.FavorFoodView = t
})(); (function() {
    "use strict";
    if (typeof Eleme === "undefined") {
        window.Eleme = {}
    }
    var e = Eleme.Common.TemplateCache;
    var i = Eleme.Model.Food,
    t = Eleme.View.FoodView;
    var o = {
        tplSelector: "#cate-single-tpl",
        imgViewWrapSelector: ".rst-menu-img-list",
        plainViewWrapSelector: ".rst-menu-list",
        cateContainerTpl: "#cate-tpl",
        tagName: "section"
    };
    function s(e, i) {
        this.id = "view" + Eleme.View.uuid++;
        this.element = null;
        this.cate = e;
        this.foodViews = {};
        this.childViews = [];
        this.buffer = null;
        this.init(i)
    }
    s.prototype.init = function(e) {
        e = e || {};
        this.createFoodModel();
        this.makeFoodView();
        Eleme.View.views[this.id] = this
    };
    s.prototype.$el = function() {
        if (!this.element) {
            this.element = $("#" + this.id)
        }
        return this.element
    };
    s.prototype.remove$el = function() {
        var e = this.childViews.length;
        if (this.element) {
            this.element = null
        }
        while (e--) {
            this.childViews[e].remove$el()
        }
    };
    s.prototype.createFoodModel = function() {
        var e, t, o, s, l = this.cate.foods.img,
        n = this.cate.foods.plain,
        h = [],
        r = [];
        for (e = 0, o = l.length; e < o; e++) {
            l[e].activityImages = this.cate.activityImages;
            h.push(new i(l[e]))
        }
        for (t = 0, s = n.length; t < s; t++) {
            n[t].activityImages = this.cate.activityImages;
            r.push(new i(n[t]))
        }
        this.cate.foods.img = h;
        this.cate.foods.plain = r
    };
    s.prototype.makeFoodView = function() {
        var e, i;
        e = new l(this.cate.foods.img, "img");
        i = new l(this.cate.foods.plain, "plain");
        this.childViews.push(e, i)
    };
    s.prototype.render = function(i) {
        var t = e.get(o.cateContainerTpl);
        this.buffer = i;
        i.begin(o.tagName);
        this.beforeRender(i);
        i.push($.trim(t(this.cate)));
        this.renderFood(i);
        this.afterRender(i);
        return this
    };
    s.prototype.beforeRender = function(e) {
        this.addPropertyToBuffer(e);
        e.pushOpenTag()
    };
    s.prototype.afterRender = function(e) {
        e.pushCloseTag()
    };
    s.prototype.addPropertyToBuffer = function(e) {
        e.setId(this.id).setClass(o.className)
    };
    s.prototype.renderFood = function(e) {
        var i, t;
        for (i = 0, t = this.childViews.length; i < t; i++) {
            this.childViews[i].render(e)
        }
    };
    s.prototype.clearBuffer = function() {
        var e;
        this.buffer = null;
        for (e = this.childViews.length; e--;) {
            this.childViews[e].clearBuffer()
        }
    };
    s.prototype.findByFoodId = function(e) {
        var i, t;
        for (i = this.childViews.length; i--;) {
            if (t = this.childViews[i].findByFoodId(e)) {
                return t
            }
        }
    };
    s.prototype.scrollToView = function() {
        var e = "html, body",
        i = this.$el().offset().top;
        $(e).animate({
            scrollTop: i + "px"
        })
    };
    s.prototype.scrollFoodToView = function(e) {
        var i;
        for (i = this.childViews.length; i--;) {
            this.childViews[i].scrollFoodToView(e)
        }
    };
    s.prototype.sort = function(e, i) {
        var t;
        for (t = this.childViews.length; t--;) {
            this.childViews[t].sort(e, i)
        }
    };
    function l(e, i) {
        this.id = "view" + Eleme.View.uuid++;
        this.element = null;
        this.content = e;
        this.type = i;
        this.childViews = [];
        this.buffer = null;
        this.init()
    }
    l.prototype.init = function() {
        this.createChildView()
    };
    l.prototype.$el = function() {
        if (!this.element) {
            this.element = $("#" + this.id)
        }
        return this.eleemnt
    };
    l.prototype.remove$el = function() {
        var e = this.childViews.length;
        if (this.element) {
            this.element = null
        }
        while (e--) {
            this.childViews[e].remove$el()
        }
    };
    l.prototype.createChildView = function() {
        var e, i, o;
        for (e = 0, i = this.content.length; e < i; e++) {
            o = new t(this.content[e]);
            this.childViews.push(o)
        }
        this.originChildViews = this.childViews
    };
    l.prototype.render = function(e) {
        if (this.content.length > 0) {
            this.buffer = e;
            e.begin("ul");
            e.setId(this.id);
            if (this.type === "img") {
                e.setClass("rst-menu-img-list")
            } else {
                e.setClass("rst-menu-list")
            }
            e.pushOpenTag();
            this._renderFood(this.childViews, e);
            e.pushCloseTag()
        }
    };
    l.prototype._renderFood = function(e, i) {
        var t, o;
        for (t = 0, o = e.length; t < o; t++) {
            e[t].render(i)
        }
    };
    l.prototype.clearBuffer = function() {
        this.buffer = null;
        for (var e = this.childViews.length; e--;) {
            this.childViews[e].buffer = null
        }
    };
    l.prototype.findByFoodId = function(e) {
        for (var i = this.childViews.length; i--;) {
            if (this.childViews[i].food.values.id === e) {
                return this.childViews[i]
            }
        }
    };
    l.prototype._destroyFoodView = function() {
        var e;
        while (e = this.childViews.pop()) {
            delete Eleme.View.views[e.id];
            e.destroy()
        }
    };
    l.prototype.scrollFoodToView = function(e) {
        var i = this.childViews.length;
        while (i--) {
            if (e === this.childViews[i].food.values.id) {
                this.childViews[i].scrollToView();
                break
            }
        }
    };
    l.prototype.sort = function(e, i) {
        if (e === "default") {
            this.childViews = this.originChildViews
        } else {
            if (this.childViews.length > 0) {
                this.childViews = _.sortBy(this.childViews,
                function(i) {
                    return i.food.values[e]
                })
            }
            if (i === "asc") {
                this.childViews.reverse()
            }
        }
    }; ! Eleme.View && (Eleme.View = {});
    Eleme.View.CateView = s;
    Eleme.View.FoodCollectionView = l
})(); (function() {
    "use strict";
    if (typeof Eleme === "undefined") {
        window.Eleme = {}
    }
    var e = Eleme.Model.BasketFood,
    t = Eleme.View.BasketFoodView;
    var s = {
        clearBtnSelector: ".basket_clear_btn",
        addToBasketTopic: "addToBasket",
        clearBasketTopic: "clearBasket",
        elemWrapper: '<div class="rcart-list-wrapper single_basket ui_c<%- data.id + 1 %>"></div>',
        elemTitleTpl: '<h4 class="rcart-title"><%- data.id + 1 %>号篮子 <a class="rcart-clear basket_clear_btn">[清空]</a></h4>',
        elemList: '<ul class="rcart-list basket_list"></ul>',
        emptyBasketHint: '<p class="rcart-empty">篮子是空的</p>'
    };
    function i(e, t) {
        this.$el = null;
        this.basket = e;
        this.basketFoodViews = {};
        this.init(t)
    }
    i.prototype.init = function() {
        var e = _.template(s.elemWrapper, this.basket.values);
        this.$el = $(e);
        this.$el.css("max-height", $(window).height() - 155);
        this.bindEvents()
    };
    i.prototype.bindEvents = function() {
        this.$el.on("click", s.clearBtnSelector, $.proxy(this.clearBasket, this))
    };
    i.prototype.render = function() {
        this.renderFoods();
        return this
    };
    i.prototype.renderFoods = function() {
        var i, a, l, o, n, r, p, h = this.basket.values.foods,
        c = $(s.elemList),
        d = _.template(s.elemTitleTpl);
        this.$el.empty();
        if (h.length === 0) {
            this.$el.append($(s.emptyBasketHint));
            return
        }
        for (i = h.length; i--;) {
            o = new e(h[i]);
            o.values.groupId = this.basket.values.id;
            r = new t(o).render();
            c.append(r.$el);
            l = h[i].garnishes;
            for (a = l.length; a--;) {
                n = new e(l[a]);
                n.values.isGarnish = true;
                n.values.groupId = o.values.groupId;
                n.values.parentFoodId = o.values.id;
                p = new t(n).render();
                c.append(p.$el)
            }
        }
        this.$el.append(d(this.basket.values), c)
    };
    i.prototype.sync = function() {
        this.basket.sync()
    };
    i.prototype.clearBasket = function() {
        this.basket.clear()
    };
    i.prototype.show = function() {
        var e = -this.$el.outerHeight();
        if (Modernizr.csstransitions) {
            this.$el.css("top", e);
            this.$el.addClass("ui_open")
        } else {
            this.$el.animate({
                top: e
            },
            300,
            function() {
                $(this).addClass("ui_open")
            })
        }
    };
    i.prototype.hide = function() {
        if (Modernizr.csstransitions) {
            this.$el.css("top", "0px");
            this.$el.removeClass("ui_open")
        } else {
            this.$el.animate({
                top: "0px"
            },
            300,
            function() {
                $(this).removeClass("ui_open")
            })
        }
    };
    i.prototype.toggle = function() {
        this.$el.hasClass("ui_open") ? this.hide() : this.show()
    };
    i.prototype.remove = function() {
        this.$el.remove()
    }; ! Eleme.View && (Eleme.View = {});
    Eleme.View.BasketView = i
})(); (function() {
    "use strict";
    if (typeof Eleme === "undefined") {
        window.Eleme = {}
    }
    var e = Eleme.Common.TemplateCache;
    var t = {
        tplSelector: "#food-comment-tpl",
        imgSelector: ".c_img",
        elemTag: "<li></li>",
        className: "rst-drawer-citem",
        commentTpl: "#comment-tpl"
    };
    function m(e, t) {
        this.$el = null;
        this.comment = e;
        this.init(t)
    }
    m.prototype.init = function() {
        this.$el = $(t.elemTag).addClass(t.className)
    };
    m.prototype.render = function() {
        var m = e.get(t.commentTpl);
        this.$el.html(m($.extend({},
        this.comment.values)));
        return this
    };
    m.prototype.destroy = function() {
        this.$el.remove()
    }; ! Eleme.View && (Eleme.View = {});
    Eleme.View.CommentView = m
})(); (function() {
    "use strict";
    if (typeof Eleme === "undefined") {
        window.Eleme = {}
    }
    var o = Eleme.Common.Evt,
    e = Eleme.Common.TemplateCache;
    var t = {
        bookBtnSelector: ".favor_btn",
        foodInfoTpl: "#comment-food-info-tpl",
        elemTag: "<header></header>",
        className: "rst-drawer-header",
        bookStateClass: "ui_favored"
    };
    function i(o) {
        this.food = o;
        this.events = {};
        this.init()
    }
    $.extend(i.prototype, o);
    i.prototype.init = function() {
        this.$el = $(t.elemTag).addClass(t.className);
        this.bindEvents();
        this.listenTo(this.food, "favorStateChange.commentFood", $.proxy(this.favorStateHandler, this))
    };
    i.prototype.bindEvents = function() {
        this.$el.on("click", t.bookBtnSelector, $.proxy(this.bookFood, this))
    };
    i.prototype.bookFood = function() {
        if (ELEME.authed) {
            this.food.favor()
        } else {
            window.location.href = ELEME.formerBaseUrl + "/login"
        }
    };
    i.prototype.render = function() {
        var o = e.get(t.foodInfoTpl);
        this.$el.html(o($.extend({},
        this.food.values)));
        return this
    };
    i.prototype.favorStateHandler = function() {
        if (this.food.values.isFavor) {
            this.$el.find(t.bookBtnSelector).addClass(t.bookStateClass)
        } else {
            this.$el.find(t.bookBtnSelector).removeClass(t.bookStateClass)
        }
    };
    i.prototype.destroy = function() {
        this.stopListening(this.food, "favorStateChange.commentFood");
        this.$el.off().remove()
    }; ! Eleme.View && (Eleme.View = {});
    Eleme.View.FoodCommentView = i
})(); (function() {
    "use strict";
    if (typeof Eleme === "undefined") {
        window.Eleme = {}
    }
    var t = Eleme.Common.PubSub,
    e = Eleme.Common.RenderBuffer,
    o = Eleme.Common.TemplateCache;
    var a = Eleme.View.CateView;
    var i = {
        rstMenus: "#rst_menus",
        menuCate: "#menu_category",
        cateWrapper: "#menu_cate_wrapper",
        cateList: "#menu_cate_list",
        cateItem: ".cate_item",
        cateName: ".cate_name",
        cateToggle: "#cate_toggle",
        activityCateList: "#activity_cate_list",
        foldItemSelector: ".fold_item",
        menuToolbar: "#menu_toolbar",
        toolbarText: "#toolbar_text",
        toolbarCate: "#toolbar_category",
        toolbarToggle: "#toolbar_toggle",
        toolbarDropdown: "#toolbar_dropdown",
        sortBtn: ".sort_btn",
        cateView: "#cate_view",
        menuTitle: ".menu_title",
        addBtn: ".add_btn",
        fixNav: "#toolbar_toggle",
        foodName: ".food_name",
        foodRating: ".food_rating",
        foodImg: ".food_img"
    };
    var s = {
        menuCateItem: "#cate-nav",
        normalCateList: '<ul id="menu_cate_list" class="rst-cate-list"></ul>',
        activityCateList: '<ul id="activity_cate_list" class="rst-cate-list activity"></ul>',
        menuCateToggle: '<a id="cate_toggle" class="rst-cate-toggle caret"><span class="more">更多分类</span><span class="less">收起</span></a>',
        menuCateName: ["<% if (data.activityIcons) { %>", "<% _.each(data.activityIcons, function(icon) { %>", '<img class="icon-rst-badge" src="<%- ELEME.fussHost + icon.url %>" title="<%- icon.desc %>" />&nbsp;', "<% }); %>", "<% } %>", '<% if (data.activityType === "secKill") { %>', '<i class="icon-rst-badge half-price"></i>&nbsp;', "<% } %>", "<%- data.categ %>"].join(""),
        menuToolbar: ['<div id="menu_toolbar" class="rst-menu-toolbar">', '<div id="toolbar_text" class="rst-toolbar-text"><%= data.toolbarText %></div>', '<div class="rst-menu-tool">', '<div id="toolbar_category" class="eleme_dropdown rst-tool-cate">', '<a id="toolbar_toggle" class="e_toggle rst-tool-toggle caret">美食分类</a>', '<div id="toolbar_dropdown" class="e_dropdown rst-tool-dropdown"><%= data.fixCateNavs %></div>', "</div>", '<a class="rst-tool-item sort_btn ui_on" data-sort="default">默认排序</a>', '<a class="rst-tool-item sort_btn" data-sort="rating">评分<i class="glyph-sort"></i></a>', '<a class="rst-tool-item sort_btn" data-sort="sales">销量<i class="glyph-sort"></i></a>', '<a class="rst-tool-item sort_btn" data-sort="price">价格<i class="glyph-sort"></i></a>', "</div>", "</div>"].join("")
    };
    var n = {
        menuFilterTopic: "filterFood",
        foodScrollTopic: "foodScroll",
        addFoodTopic: "addFoodToBasketAnim",
        getBasketInfoTopic: "getBasketInfo",
        fetchFoodDoneTopic: "fetchFoodDone",
        restaurantDoneTopic: "restaurantDone",
        basketSyncSuccessTopic: "basketSyncSuccess",
        favorFoodInitTopic: "favorFoodInit",
        addAnimEndTopic: "addAnimEnd",
        basketInitTopic: "basketInit",
        insertMenuTopic: "insertMenu",
        menuSelector: ".main_food_panel",
        cartTipSelector: "#clear_cart_panel"
    };
    function r(t) {
        this.$el = null;
        this.buffer = null;
        this.cates = [];
        this.cateViews = [];
        this.lastFoodsId = [];
        this.init(t)
    }
    r.prototype.init = function() {
        this.$el = $(i.rstMenus);
        this.bindEvents();
        this.subscribeTopic()
    };
    r.prototype.subscribeTopic = function() {
        t.subscribe(n.fetchFoodDoneTopic,
        function() {
            var t;
            t = this.makeCateNavContent(this.cates);
            this.renderCateNav(t);
            this.addToolbar(t);
            this.render();
            this.checkFood();
            setTimeout($.proxy(this.initScrollSpy, this), 2e3)
        },
        this);
        t.subscribe(n.foodScrollTopic, this.scrollFoodById, this);
        t.subscribe(n.basketSyncSuccessTopic, this.tagFoodView, this);
        t.subscribe(n.basketInitTopic, this.tagFoodView, this);
        t.subscribe(n.menuFilterTopic,
        function(t, e) {
            if (t.keyword === "") {
                e.call(null, {
                    food: []
                });
                return
            }
            var o = this.cates.length,
            a, i, s, n = [],
            r = t.keyword;
            while (o--) {
                i = this.cates[o].foods;
                s = i.img.concat(i.plain);
                for (a = s.length; a--;) {
                    if (s[a].values.searchIndex && s[a].values.searchIndex.indexOf(r) > -1) {
                        n.push(s[a].values)
                    }
                }
            }
            if (n.length > 0) {
                _gaq.push(["_trackEvent", "topbarSearch", "hasResult", "inRestaurant", n.length])
            } else {
                _gaq.push(["_trackEvent", "topbarSearch", "noResult", "inRestaurant", 0])
            }
            e.call(null, {
                foods: n
            })
        },
        this);
        t.subscribe(n.restaurantDoneTopic,
        function(e) {
            var o, a, i, s = [],
            r = e.favorFoodIds;
            if (r.length === 0) {
                t.publish(n.favorFoodInitTopic, s);
                return
            }
            for (o = r.length; o--;) {
                for (a = this.cateViews.length; a--;) {
                    if (i = this.cateViews[a].findByFoodId(r[o])) {
                        i.food.values.isFavor = true;
                        i.favorStateHandler();
                        s.push(i.food);
                        break
                    }
                }
            }
            t.publish(n.favorFoodInitTopic, s)
        },
        this);
        t.subscribe(n.addFoodTopic,
        function(e) {
            this.currentAddFood = e;
            t.subscribeOnce(n.basketSyncSuccessTopic, $.proxy(this.addFoodAnim, this))
        },
        this)
    };
    r.prototype.bindEvents = function() {
        var t = this;
        $(document).on("click", e).on("click", o);
        function e() {
            var t = $(n.menuSelector),
            e = t.parent(".rst-d-act");
            if (!e.hasClass("ui_open")) {
                return
            }
            e.removeClass("ui_open");
            t.remove()
        }
        function o() {
            var t = $(n.cartTipSelector);
            if (t.length > 0) {
                t.remove()
            }
        }
        this.$el.on("click", i.addBtn,
        function() {
            _gaq.push(["_trackEvent", "restaurant", "addFood", "fromNormal"])
        });
        this.$el.on("click", i.foodName,
        function() {
            _gaq.push(["_trackEvent", "restaurant", "showComment", "foodName"])
        });
        this.$el.on("click", i.foodImg,
        function() {
            _gaq.push(["_trackEvent", "restaurant", "showComment", "foodImage"])
        });
        this.$el.on("click", i.foodRating,
        function() {
            _gaq.push(["_trackEvent", "restaurant", "showComment", "foodRating"])
        });
        this.$el.on("click", i.fixNav,
        function() {
            if (!$(this).parent().hasClass("open")) {
                _gaq.push(["_trackEvent", "restaurant", "openFixCateNav"])
            }
        });
        this.$el.on("click", i.cateToggle,
        function() {
            var e = $(this);
            if (e.hasClass("ui_toggled")) {
                $(i.cateList).find(i.foldItemSelector).addClass("hide")
            } else {
                $(i.cateList).find(i.foldItemSelector).removeClass("hide");
                _gaq.push(["_trackEvent", "restaurant", "openTopCateNav"])
            }
            e.toggleClass("ui_toggled");
            window.setTimeout($.proxy(t.refreshScrollSpy, t), 0)
        });
        this.$el.on("click", i.cateName,
        function() {
            var e = $(this).data("cateid"),
            o = "topNav";
            t.scrollFoodByCate(e);
            if ($(this).parents(i.toolbarDropdown).length) {
                $(i.toolbarToggle).trigger("click");
                o = "fixNav"
            }
            _gaq.push(["_trackEvent", "restaurant", "useCateNav", o]);
            _gaq.push(["_trackEvent", "foodCateNav", o])
        });
        this.$el.on("click", i.sortBtn,
        function() {
            var e = $(this),
            o = e.attr("data-sort");
            if (o === "default") {
                if (!e.hasClass("ui_on")) {
                    e.addClass("ui_on").siblings().removeClass("ui_on ui_desc");
                    t.sort(o)
                }
                return
            }
            if (!e.hasClass("ui_on")) {
                if (o === "price") {
                    e.addClass("ui_on").siblings().removeClass("ui_on ui_desc")
                } else {
                    e.addClass("ui_on ui_desc").siblings().removeClass("ui_on ui_desc")
                }
            }
            if (e.hasClass("ui_desc")) {
                e.removeClass("ui_desc");
                t.sort(o, "asc")
            } else {
                e.addClass("ui_desc");
                t.sort(o)
            }
        });
        $(document.body).on("click", ".food_view",
        function(t) {
            var e = Eleme.View.views[this.id];
            while (e) {
                if (e["click"]) {
                    break
                }
                e = e.parentView
            }
            if (e) {
                e.click(t);
                t.stopPropagation()
            }
        })
    };
    r.prototype.fetch = function() {
        this.parseMenuData(window.menu)
    };
    r.prototype.parseMenuData = function(e) {
        var o, a, i, s, r;
        this.cates = $.extend(true, [], e);
        for (o = this.cates.length; o--;) {
            s = this.cates[o].foods;
            i = s.length;
            this.cates[o].total = i;
            r = {
                img: [],
                plain: []
            };
            for (a = 0; a < i; a++) {
                s[a].img ? r.img.push(s[a]) : r.plain.push(s[a])
            }
            this.cates[o].foods = r
        }
        t.publish(n.fetchFoodDoneTopic, e)
    };
    r.prototype.render = function() {
        var o, i, s, r, l;
        l = this.buffer = new e("div");
        l.setId("cate_view").setClass("rst-menu-block");
        l.pushOpenTag();
        for (o = 0, s = this.cates.length; o < s; o++) {
            r = new a(this.cates[o]);
            this.cateViews.push(r);
            r.render(l)
        }
        l.pushCloseTag();
        this.$el.append(l.buffer);
        t.publish(n.insertMenuTopic);
        for (i = this.cateViews.length; i--;) {
            this.cateViews[i].clearBuffer()
        }
        this.buffer = null;
        this.$el.removeClass("hide")
    };
    r.prototype.makeCateNavContent = function(t) {
        t = t || [];
        var e, a, i = 0,
        n = 0,
        r = "",
        l = "",
        c = o.get(s.menuCateItem);
        for (e = 0, a = t.length; e < a; e++) {
            if (t[e].isActivity) {
                n++;
                l += c(t[e])
            } else {
                i++;
                r += c(t[e])
            }
        }
        return {
            activity: {
                num: n,
                buffer: l
            },
            normal: {
                num: i,
                buffer: r
            }
        }
    };
    r.prototype.renderCateNav = function(t) {
        var o = t.normal.buffer,
        a = t.activity.buffer,
        n = t.normal.num,
        r = t.activity.num,
        l = this.$el.find(i.cateWrapper);
        var c = new e;
        if (r > 0) {
            c.begin("ul");
            c.setId("activity_cate_list");
            c.setClass("rst-cate-list activity");
            c.pushOpenTag();
            c.push(a);
            c.pushCloseTag()
        }
        c.begin("ul");
        c.setId("menu_cate_list");
        c.setClass("rst-cate-list");
        c.pushOpenTag();
        c.push(o);
        if (n > 12) {
            if (n % 4 === 0) {
                c.push('<li class="cate_item cate-item fold_item"></li>')
            }
            c.pushCloseTag();
            c.push(s.menuCateToggle)
        }
        c.pushCloseTag();
        l.html(c.buffer);
        if (n > 12) {
            l.find(i.cateList).find(i.cateItem + ":gt(10)").addClass("fold_item hide")
        }
    };
    r.prototype.addToolbar = function(t) {
        var o, a, n = "",
        r = this.cates[0],
        l = _.template(s.menuToolbar),
        c = _.template(s.menuCateName);
        var d = new e;
        if (t.activity.num > 0) {
            d.begin("ul");
            d.setClass("rst-cate-list activity");
            d.pushOpenTag();
            d.push(t.activity.buffer);
            d.pushCloseTag()
        }
        d.begin("ul");
        d.setClass("rst-cate-list");
        d.pushOpenTag();
        d.push(t.normal.buffer);
        d.pushCloseTag();
        n = c(r);
        o = {
            toolbarText: n,
            fixCateNavs: d.buffer
        };
        a = l(o);
        this.$el.find(i.menuCate).after(a);
        this.$el.find(i.toolbarCate).uDropdown()
    };
    r.prototype.initScrollSpy = function() {
        var t, e, o;
        t = this.cateViews[0];
        if (!t) {
            return
        }
        e = $.trim(t.$el().find(i.menuTitle).text());
        o = t.$el().find(i.menuTitle).html();
        $(i.menuToolbar).scrollspy({
            min: $(i.menuToolbar).offset().top,
            max: $(document).height(),
            onEnter: function(t) {
                $(t).addClass("ui_fixed")
            },
            onLeave: function(t) {
                $(t).removeClass("ui_fixed");
                $(i.toolbarText).attr("title", e).html(o);
                $(i.toolbarDropdown).find(i.cateItem).removeClass("ui_active")
            }
        });
        _.each(this.cateViews,
        function(t) {
            var e = t.$el().find(i.menuTitle),
            o = e.html(),
            a = $.trim(e.text()),
            s = e.offset().top,
            n = s + e.parent().height() - 1;
            e.scrollspy({
                min: s,
                max: n,
                onEnter: function() {
                    $(i.toolbarText).html(o).attr("title", a);
                    $(i.toolbarDropdown).find("[data-cateid=" + t.cate.categId + "]").addClass("ui_active")
                },
                onLeave: function() {
                    $(i.toolbarDropdown).find("[data-cateid=" + t.cate.categId + "]").removeClass("ui_active")
                }
            });
            e = s = n = null
        });
        $(window).trigger("scroll.scrollspy")
    };
    r.prototype.refreshScrollSpy = function() {
        $(window).unbind("scroll.scrollspy");
        this.initScrollSpy()
    };
    r.prototype.sort = function(o, a) {
        var s, r, l, c, d;
        _gaq.push(["_trackEvent", "restaurant", "sortFood", o]);
        l = this.buffer = new e("div");
        l.setId("cate_view").setClass("rst-menu-block");
        l.pushOpenTag();
        for (s = 0, r = this.cateViews.length; s < r; s++) {
            c = this.cateViews[s];
            c.sort(o, a);
            c.render(l);
            c.remove$el()
        }
        l.pushCloseTag();
        $(i.cateView).replaceWith(l.buffer);
        d = t.publish(n.getBasketInfoTopic);
        if (d) {
            this.tagFoodView(d)
        }
    };
    r.prototype.tagFoodView = function(t) {
        var e, o, a, i = [],
        s,
        n,
        r,
        l;
        r = _.flatten($.extend(true, [], t.groups), true);
        for (e = r.length; e--;) {
            l = r[e].garnishes;
            a = r[e].id;
            if (c(r[e])) {
                i.push(r[e])
            }
            for (o = l.length; o--;) {
                if (c(l[o])) {
                    i.push(l[o])
                }
            }
        }
        this.lastFoodsId || (this.lastFoodsId = []);
        for (e = this.lastFoodsId.length; e--;) {
            n = this.lastFoodsId[e];
            d(this.cateViews, n, true)
        }
        for (e = i.length; e--;) {
            s = i[e];
            d(this.cateViews, s, false)
        }
        function c(t) {
            var e;
            for (e = i.length; e--;) {
                if (i[e].id === t.id) {
                    i[e].quantity += t.quantity;
                    return
                }
            }
            return true
        }
        function d(t, e, o) {
            var a, i;
            for (a = t.length; a--;) {
                if (i = t[a].findByFoodId(e.id)) {
                    i.food.values.inBasket = o ? 0 : e.quantity;
                    i.food.trigger("basketStateChange");
                    break
                }
            }
        }
        this.lastFoodsId = i
    };
    r.prototype.scrollFoodByCate = function(t) {
        var e = this.cateViews.length;
        while (e--) {
            if (this.cateViews[e].cate.categId === t) {
                this.cateViews[e].scrollToView();
                return
            }
        }
    };
    r.prototype.scrollFoodById = function(t) {
        var e = this.cateViews.length;
        while (e--) {
            if (this.cateViews[e].scrollFoodToView(t)) {
                return
            }
        }
    };
    r.prototype.addFoodAnim = function() {
        var e, o, a = $(window).scrollTop(),
        i = this.currentAddFood.$el().find(".act_btns"),
        s = $(".current_basket_tile").offset(),
        r = $('<span id="anim_price_tip" class="rst-animate-tip"></span>');
        o = i.offset(),
        e = {
            left: o.left,
            top: o.top - a
        };
        r.html(this.currentAddFood.food.values.price).css({
            left: e.left + "px",
            top: e.top + "px"
        }).appendTo(this.$el).animate({
            left: s.left,
            top: s.top - a
        },
        500, "linear",
        function() {
            r.remove();
            t.publish(n.addAnimEndTopic)
        })
    };
    r.prototype.checkFood = function() {
        var t, e, o = window.location.hash;
        if (o.length <= 1) {
            return
        }
        e = o.substr(1).split("/");
        if (e[0] === "food") {
            t = window.parseInt(e[1], 10);
            this.scrollFoodById(t)
        }
    }; ! Eleme.Controller && (Eleme.Controller = {});
    Eleme.Controller.MenuManager = r
})(); (function() {
    "use strict";
    if (typeof Eleme === "undefined") {
        window.Eleme = {}
    }
    var t = Eleme.Common.PubSub,
    e = Eleme.Common.TemplateCache;
    var s = Eleme.Model.Basket,
    i = Eleme.View.BasketView;
    var a = {
        basketSelector: "#rst_cart",
        basketWrapSelector: ".basket_wrap",
        basketSwitcherWrapSelector: ".basket_switcher",
        basketSwitcherTipSelector: ".switcher_toggle",
        basketTileSelector: ".single_tile",
        currentBasketTileSelector: ".current_basket_tile",
        simpleInfoSelector: ".basket_food_info",
        cartCheckoutBtnSelector: ".c_c",
        modalBodySelector: ".basket_content",
        checkoutModalSelector: "#modal_phone",
        clearCartTopic: "clearCart",
        showMainFoodTopic: "showMainFood",
        invalidBasketTopic: "invalidBasket",
        addFoodTopic: "addFoodToBasket",
        removeFoodTopic: "removeFoodBasket",
        basketSyncSuccessTopic: "basketSyncSuccess",
        basketSyncErrorTopic: "basketSyncError",
        getBasketInfoTopic: "getBasketInfo",
        addAnimEndTopic: "addAnimEnd",
        basketInitTopic: "basketInit",
        insertBasketTopic: "insertBasket",
        basketTipTpl: "<%- data.basketId %>号篮子(<%- data.basketNum %>)",
        basketTileTpl: '<li class="rcart-no single_tile <%- data.tileClass %>" data-basketId="<%- data.basketId %>" data-toggle="bs-tooltip"><%- data.basketId %></li>',
        basketSimpleInfoTpl: "#basket-info-tpl",
        basketSubmitBtnTpl: "#basket-btn-tpl",
        extraTpl: "#basket-extra-tpl",
        modalTpl: "#phone-checkout-tpl",
        tileWidth: 38,
        emptyBtnHint: "篮子是空的哦",
        reachLimitBtnHint: "去买单",
        unreachLimitBtnHint: '还差 <span class="symbol-rmb"><%- data.plus %></span> 起送',
        basketDefaultNum: 6,
        basketClassPrefix: "ui_c",
        priceExtraList: [2, 3, 4, 5, 6, 7, 8, 9, 100, 101]
    };
    function r(t) {
        this.$el = null;
        this.baskets = [];
        this.basketsInfo = {};
        this.basketsView = [];
        this.currentBasket = 0;
        this.isFirstFetch = true;
        this.isCheckoutReady = false;
        this.request = null;
        this.init(t)
    }
    r.prototype.init = function() {
        this.$el = $(a.basketSelector);
        this.$el.find(a.currentBasketTileSelector).addClass(a.basketClassPrefix + (this.currentBasket + 1));
        this.subscribeTopic();
        this.bindEvents()
    };
    r.prototype.subscribeTopic = function() {
        t.subscribe(a.clearCartTopic,
        function() {
            this.clearBasket()
        },
        this);
        t.subscribe(a.getBasketInfoTopic,
        function() {
            return this.basketsInfo
        },
        this);
        t.subscribe(a.addFoodTopic,
        function(t, e) {
            e = e || {};
            e.basketId = this.currentBasket;
            t.call(null, e)
        },
        this);
        t.subscribe(a.basketSyncSuccessTopic,
        function(t, e) {
            e = e || {};
            if (t === "1") {
                t = {
                    quantity: 0,
                    total: 0,
                    groups: [],
                    extras: []
                }
            }
            var s;
            this.parseCartData(t);
            if (e.basket) {
                s = this.basketsView[this.currentBasket];
                this.render();
                if (s && s.$el.hasClass("ui_open")) {
                    s.$el.css("top", -s.$el.outerHeight())
                }
                if (!this.isFirstFetch && !s.$el.hasClass("ui_open")) {
                    s.show()
                }
            }
        },
        this);
        t.subscribe(a.basketInitTopic,
        function(e) {
            this.parseCartData(e);
            this.render();
            this.isFirstFetch = false;
            t.publish(a.insertBasketTopic)
        },
        this);
        t.subscribe(a.addAnimEndTopic,
        function() {
            var t = this.basketsView[this.currentBasket];
            this.render();
            if (t && t.$el.hasClass("ui_open")) {
                t.$el.css("top", -t.$el.outerHeight())
            }
            if (!this.isFirstFetch && !t.$el.hasClass("ui_open")) {
                t.show()
            }
        },
        this);
        t.subscribe(a.basketSyncErrorTopic,
        function() {},
        this);
        t.subscribe(a.showMainFoodTopic,
        function(t) {
            var e = this.baskets[this.currentBasket];
            t.call(null, this.currentBasket, e)
        },
        this)
    };
    r.prototype.bindEvents = function() {
        var t = this;
        this.$el.on("click", a.basketSwitcherTipSelector,
        function() {
            t.toggleBasketSwitcher()
        });
        this.$el.on("click", a.cartCheckoutBtnSelector,
        function(e) {
            if (t.isCheckoutReady) {
                if (t.basketsInfo.phoneOrder) {
                    e.preventDefault();
                    t.openCheckoutModal()
                }
            } else {
                e.preventDefault()
            }
            e.stopPropagation()
        });
        this.$el.on("click", a.basketWrapSelector,
        function() {
            if (t.basketsView[t.currentBasket].$el.hasClass("ui_open")) {
                t.basketsView[t.currentBasket].hide()
            } else {
                t.basketsView[t.currentBasket].show()
            }
        });
        this.$el.on("mouseenter", a.basketSwitcherTipSelector,
        function() {
            $(this).parent().hasClass("ui_open") ? $(this).attr("data-original-title", "关闭篮子") : $(this).attr("data-original-title", "展开篮子")
        });
        this.$el.on("mouseenter", a.basketTileSelector,
        function() {
            var e, s, i, r, n, o = 0,
            l = $(this).data("basketid"),
            c = t.baskets[l - 1],
            h = _.template(a.basketTipTpl);
            for (e = c.length; e--;) {
                i = c[e];
                o += i.quantity;
                for (s = i.garnishes.length; s--;) {
                    r = i.garnishes[s];
                    o += r.quantity
                }
            }
            n = h({
                basketId: l,
                basketNum: o
            });
            $(this).attr("data-original-title", n)
        });
        this.$el.on("click", a.basketTileSelector,
        function(e) {
            var s = $(e.target).data("basketid");
            _gaq.push(["_trackEvent", "restaurant", "basketChange", s]);
            s -= 1;
            t.switchBasket(s)
        });
        this.$el.on("mouseenter", a.basketWrapSelector,
        function() {
            if (t.baskets[0].length === 0) {
                return
            }
            t.$el.find(a.basketSwitcherTipSelector).show()
        });
        this.$el.on("mouseleave", a.basketWrapSelector,
        function(e) {
            if ($(e.relatedTarget).hasClass(a.basketSwitcherTipSelector.substr(1))) {
                return
            }
            if (t.$el.find(a.basketSwitcherWrapSelector).parent().hasClass("ui_open")) {
                return
            }
            t.$el.find(a.basketSwitcherTipSelector).hide()
        });
        this.$el.on("mouseleave", a.basketSwitcherTipSelector,
        function(e) {
            var s = $(e.target);
            if (t.$el.find(a.basketSwitcherWrapSelector).parent().hasClass("ui_open")) {
                return
            }
            s.hide()
        });
        $(window).on("resize",
        function() {
            var t = $(window).height(),
            e = $(".single_basket.ui_open");
            if ($(window).height() > 250) {
                $(".single_basket").css("max-height", t - 155);
                if (e.length) {
                    var s = e.find(".basket_list").outerHeight();
                    e.css("top", s > t - 155 ? 155 - t: -s)
                }
            }
        })
    };
    r.prototype.fetch = function() {
        this.sync("fetch")
    };
    r.prototype.parseCartData = function(t) {
        this.basketsInfo = $.extend(true, {},
        t);
        this.baskets = this.basketsInfo.groups;
        if (this.baskets.length < a.basketDefaultNum) {
            this.baskets[this.baskets.length] = []
        }
    };
    r.prototype.render = function() {
        this.updateBasketInfo();
        this.renderBasket();
        this.renderExtra();
        this.renderTile()
    };
    r.prototype.updateBasketInfo = function() {
        var t, s, i, r = false,
        n = false,
        o = e.get(a.basketSubmitBtnTpl),
        l = e.get(a.basketSimpleInfoTpl),
        c = this.$el.find(a.basketWrapSelector);
        this.$el.find(a.simpleInfoSelector + "," + a.cartCheckoutBtnSelector).remove();
        this.isCheckoutReady = false;
        if (this.basketsInfo.total === 0 && this.basketsInfo.quantity === 0) {
            t = a.emptyBtnHint;
            n = true
        } else {
            c.append(l({
                num: this.basketsInfo.quantity,
                price: this.basketsInfo.total
            }));
            if (this.basketsInfo.total >= 0 && this.basketsInfo.deliverAmount < this.basketsInfo.restaurantDeliverAmount) {
                t = _.template(a.unreachLimitBtnHint, {
                    plus: this.basketsInfo.restaurantDeliverAmount - this.basketsInfo.deliverAmount
                });
                n = true
            } else if (this.basketsInfo.deliverAmount >= this.basketsInfo.restaurantDeliverAmount) {
                t = a.reachLimitBtnHint;
                r = true;
                this.isCheckoutReady = true
            }
        }
        s = {
            btnHint: t,
            checkoutReady: r,
            phoneOrder: this.basketsInfo.phoneOrder,
            checkoutUrl: "http://" + ELEME.mainHost + "/cart/checkout"
        };
        i = $(o(s));
        n && i.addClass("disabled");
        c.append(i)
    };
    r.prototype.renderBasket = function() {
        var t, e, r, n, o = this.$el;
        for (t = 0, e = Math.min(a.basketDefaultNum, this.baskets.length); t < e; t++) {
            if (!this.basketsView[t]) {
                r = new s({
                    id: t,
                    foods: this.baskets[t]
                });
                n = new i(r).render();
                o.append(n.$el);
                this.basketsView[t] = n
            } else {
                this.basketsView[t].basket.values.foods = this.baskets[t];
                this.basketsView[t].renderFoods()
            }
        }
    };
    r.prototype.renderExtra = function() {
        var t, s, i, r, n = e.get(a.extraTpl);
        for (t = 0, s = this.basketsInfo.extras.length; t < s; t++) {
            if (this.basketsInfo.extras[t]) {
                i = this.basketsInfo.extras[t];
                r = this.basketsView[0].$el.find(".basket_list");
                if (_.contains(a.priceExtraList, i.category_id)) {
                    i.showNum = false;
                    r.append(n(i))
                } else {
                    i.showNum = true;
                    r.append(n(i))
                }
            }
        }
    };
    r.prototype.renderTile = function() {
        var t, e, s = "",
        i = _.template(a.basketTileTpl),
        r = this.$el.find(a.basketSwitcherWrapSelector);
        r.empty();
        for (t = this.baskets.length; t--;) {
            e = this.baskets[t].length === 0 ? a.basketClassPrefix + (t + 1) + " empty": a.basketClassPrefix + (t + 1);
            s += i({
                basketId: t + 1,
                tileClass: e,
                basketNum: this.baskets[t].length
            })
        }
        r.append(s);
        if (r.parent().hasClass("ui_open")) {
            if (this.baskets.length === 1) {
                this.toggleBasketSwitcher();
                return
            }
            r.parent().css("left", -a.tileWidth * this.baskets.length)
        }
        return this
    };
    r.prototype.toggleBasketSwitcher = function() {
        var t, e = this.$el.find(a.basketTileSelector).width(),
        s = this.$el.find(a.basketSwitcherWrapSelector).parent();
        if (s.hasClass("ui_open")) {
            s.removeClass("ui_open").css("left", 0);
            this.$el.find(a.basketSwitcherTipSelector).hide();
            t = "close"
        } else {
            s.addClass("ui_open").css("left", -e * this.baskets.length);
            t = "open"
        }
        _gaq.push(["_trackEvent", "restaurant", "basketSwitcher", t])
    };
    r.prototype.switchBasket = function(t) {
        var e = this.currentBasket,
        s = this.$el.find(a.currentBasketTileSelector);
        if (t === this.currentBasket) {
            return
        }
        this.currentBasket = t;
        s.removeClass(a.basketClassPrefix + (e + 1)).addClass(a.basketClassPrefix + (this.currentBasket + 1));
        this.basketsView[e].hide();
        this.basketsView[this.currentBasket].show()
    };
    r.prototype.openCheckoutModal = function() {
        var t, s = this.baskets.slice(),
        i = $(a.checkoutModalSelector),
        r = e.get(a.modalTpl);
        s.pop();
        t = r({
            basketsInfo: this.basketsInfo,
            baskets: s
        });
        if (i.length > 0) {
            i.replaceWith(t)
        } else {
            $("body").append(t)
        }
        i = $(a.checkoutModalSelector);
        i.modal("show")
    };
    r.prototype.clearBasket = function() {
        this.sync("clear")
    };
    r.prototype.sync = function(e, s) {
        var i = {
            clear: {
                url: "/cart/clear",
                type: "get"
            },
            fetch: {
                url: "/cart",
                type: "get"
            }
        },
        r = "http://" + ELEME.mainHost + i[e].url,
        n = i[e].type;
        this.request = $.ajax({
            type: n,
            url: r,
            data: s,
            dataType: "jsonp"
        }).done(function(s) {
            if (e === "fetch") {
                t.publish(a.basketInitTopic, s)
            } else {
                t.publish(a.basketSyncSuccessTopic, s)
            }
        }).fail(function(t) {})
    }; ! Eleme.Controller && (Eleme.Controller = {});
    Eleme.Controller.BasketManager = r
})(); (function() {
    "use strict";
    if (typeof Eleme === "undefined") {
        window.Eleme = {}
    }
    var e = Eleme.Common.PubSub,
    t = Eleme.Common.TemplateCache;
    var o = Eleme.Model.Comment,
    n = Eleme.View.FoodCommentView,
    i = Eleme.View.CommentView;
    var s = {
        showTopic: "showSlide",
        fetchDoneTopic: "fetchDone",
        fetchErrorTopic: "fetchError",
        commentTypeSelector: "#comment_type_cb",
        closeTipSelector: "#rst_cmt_close",
        commentContainerSelector: ".s_r_d",
        commentMaskSelector: ".s_r_m",
        commentWrapSelector: ".c_l",
        loadTipSelector: ".c_l_t",
        totalRatingTpl: "#food-rating-summary-tpl",
        singleRatingTpl: "#food-single-rating-tpl",
        commentContainerTpl: '<section class="rst-drawer-comment comment_wrap"><h4 class="rst-drawer-cheader">用户评价<span class="rst-drawer-checkbox"><input id="comment_type_cb" class="checkbox" type="checkbox" checked/><label for="comment_type_cb">有内容的评价</label></span></h4></section>',
        commentListContainerTpl: '<ul class="c_l"></ul>',
        noCommentTpl: '<p class="rst-drawer-helper">还没有人评价过这道美食</p>',
        noTextCommentTpl: '<p class="rst-drawer-helper">无有内容的评价</p>',
        lazyLoadTipTpl: '<p class="rst-drawer-helper hide c_l_t">加载中…</p>',
        maxFetchComment: 20,
        exitCommentKey: 27
    };
    function r(e) {
        this.commentViews = {};
        this.commentList = [];
        this.commentData = {};
        this.currentFood = null;
        this.currentFoodView = null;
        this.$el = null;
        this.showAnim = null;
        this.isLoading = false;
        this.commentsEnd = false;
        this.commentType = "content";
        this.pageCount = 1;
        this.request = null;
        this.init(e)
    }
    r.prototype.init = function() {
        this.$el = $(s.commentContainerSelector);
        this.subscribeTopic();
        this.bindEvents()
    };
    r.prototype.subscribeTopic = function() {
        e.subscribe(s.showTopic,
        function(e) {
            if (!e) {
                return
            }
            this.parseFoodInfo(e);
            this.pageCount = 1;
            this.commentsEnd = false;
            this.isLoading = false;
            this.commentType = "content";
            this.fetchComment({
                foodId: this.currentFood.values.id,
                page: this.pageCount
            },
            {
                isMore: false,
                commentType: this.commentType
            });
            this.show()
        },
        this);
        e.subscribe(s.fetchDoneTopic,
        function(e, t) {
            var o, n;
            if (e.comments.length > 0) {
                this.pageCount++
            }
            if (e.comments.length < s.maxFetchComment) {
                this.commentsEnd = true
            }
            if (!t.isMore && !t.changeCommentType) {
                n = this.computeRating(e.ratings);
                if (typeof n !== "undefined") {
                    this.renderRating(n)
                }
            }
            o = this.$el.find(s.loadTipSelector);
            if (o.size() > 0) {
                o.addClass("hide")
            }
            this.parseComments(e, t.isMore);
            this.renderComments(t);
            this.isLoading = false
        },
        this)
    };
    r.prototype.fetchComment = function(t, o) {
        var n = {
            page: t.page
        },
        i = "http://" + ELEME.mainHost + "/food/" + t.foodId + "/rating";
        if (o.commentType === "content") {
            n.has_text = 1
        } else if (o.commentType === "all") {
            n.has_text = 0
        }
        this.request = $.ajax({
            type: "get",
            url: i,
            data: n,
            dataType: "jsonp"
        }).done(function(t) {
            e.publish(s.fetchDoneTopic, t, o)
        }).fail(function(t, o, n) {
            e.publish(s.fetchErrorTopic, n)
        })
    };
    r.prototype.parseFoodInfo = function(e) {
        this.currentFood = e;
        this.currentFoodView = new n(this.currentFood);
        this.$el.append(this.currentFoodView.render().$el)
    };
    r.prototype.computeRating = function(e) {
        var t, o, n, i, s = [],
        r = 0,
        m = 0,
        l = [],
        c = {};
        for (o in e) {
            if (typeof(o - 1) === "number") {
                l[o - 1] = e[o];
                r += window.parseInt(o, 10) * e[o];
                m += e[o]
            }
        }
        this.currentFood.values.ratingTotal = r;
        this.currentFood.values.commentTotal = m;
        if (m === 0) {
            return
        }
        n = (r / m).toFixed(1);
        c = {
            total: m,
            rating: n,
            star: Math.round(n * 2)
        };
        for (t = l.length; t--;) {
            i = l[t] / m;
            s.push({
                star: t + 1,
                percent: (i * 100).toFixed(1),
                width: 80 * i + "px"
            })
        }
        return {
            total: c,
            ratingDetail: s
        }
    };
    r.prototype.renderRating = function(e) {
        e = e || {};
        var o, n, i = "",
        r = e.ratingDetail || [],
        m = $('<ul class="rating-diagram"></ul>'),
        l = $('<section class="rst-drawer-rating group"></section>'),
        c = t.get(s.totalRatingTpl),
        a = t.get(s.singleRatingTpl);
        for (o = 0, n = r.length; o < n; o++) {
            i += a(r[o])
        }
        m.append(i);
        l.append(c(e.total), m);
        this.$el.append(l)
    };
    r.prototype.parseComments = function(e, t) {
        if (typeof e === "boolean" && typeof t === "undefined") {
            t = e;
            e = {}
        }
        if (t) {
            this.commentData.comments[this.commentData.comments.length] = e.comments
        } else {
            this.commentData.ratings = e.ratings;
            this.commentData.comments = [e.comments]
        }
    };
    r.prototype.renderComments = function(e) {
        e = e || {};
        var t, o = _.last(this.commentData.comments),
        n = this.$el.find(s.commentWrapSelector);
        if (e.changeCommentType) {
            this._destroyComment();
            n.empty();
            if (o.length === 0) {
                n.append(s.noTextCommentTpl);
                return
            }
            this._renderComments(o, n)
        } else if (e.isMore) {
            this._renderComments(o, n)
        } else {
            if (this.currentFood.values.commentTotal === 0) {
                this.$el.append(s.noCommentTpl);
                return
            }
            t = $(s.commentContainerTpl);
            n = $(s.commentListContainerTpl);
            if (o.length === 0) {
                n.append(s.noTextCommentTpl);
                t.append(n, s.lazyLoadTipTpl);
                this.$el.append(t);
                return
            }
            this._renderComments(o, n);
            t.append(n, s.lazyLoadTipTpl);
            this.$el.append(t)
        }
    };
    r.prototype._renderComments = function(e, t) {
        var n, s, r, m;
        for (n = 0, s = e.length; n < s; n++) {
            this.commentList.push(r = new o(e[n]));
            m = new i(r);
            this.commentViews[r.values.id] = m;
            t.append(m.render().$el)
        }
    };
    r.prototype.loadMore = function() {
        if (this.isLoading || this.commentsEnd) {
            return
        }
        this.$el.find(s.loadTipSelector).removeClass("hide");
        this.fetchComment({
            foodId: this.currentFood.values.id,
            page: this.pageCount
        },
        {
            isMore: true,
            commentType: this.commentType
        });
        this.isLoading = true
    };
    r.prototype.checkBottom = function() {
        var e = this.$el.scrollTop(),
        t = this.$el[0].scrollHeight;
        if (t - e < $(window).height() + 100) {
            this.loadMore()
        }
    };
    r.prototype.show = function() {
        var e = this;
        this.showAnim = $(s.commentMaskSelector).fadeIn({
            complete: function() {
                e.showAnim = null
            }
        });
        $(document).on("keydown.slide",
        function(t) {
            if (t.keyCode === s.exitCommentKey) {
                if (e.showAnim) {
                    e.showAnim.stop();
                    e.showAnim = null
                }
                e.hide()
            }
        });
        $(document.body).addClass("ui_no_scroll");
        this.$el.parent().addClass("ui_slide_in");
        this.$el.on("scroll.slide", $.proxy(this.checkBottom, this))
    };
    r.prototype.hide = function() {
        if (this.hideAnim) {
            return
        }
        var e = this;
        if (this.request) {
            this.request.abort();
            this.request = null
        }
        this.hideAnim = $(s.commentMaskSelector).fadeOut({
            complete: function() {
                e._destroyAll();
                e.hideAnim = null
            }
        });
        this.$el.off("scroll.slide");
        this.$el.parent().removeClass("ui_slide_in");
        $(document).off("keydown.slide");
        $(document.body).removeClass("ui_no_scroll")
    };
    r.prototype.bindEvents = function() {
        var e = this;
        $(document).on("click.mask", s.commentMaskSelector + "," + s.closeTipSelector,
        function() {
            if (e.showAnim) {
                e.showAnim.stop();
                e.showAnim = null
            }
            e.hide();
            return false
        });
        this.$el.on("change", s.commentTypeSelector,
        function(t) {
            var o, n = $(t.target);
            if (n.is(":checked")) {
                o = "content"
            } else {
                o = "all"
            }
            _gaq.push(["_trackEvent", "restaurant", "toggleCommentType"]);
            e.changeCommentType(o)
        })
    };
    r.prototype.changeCommentType = function(e) {
        if (!this.currentFood) {
            return
        }
        this.commentType = e || "all";
        this.pageCount = 1;
        this.isLoading = true;
        this.commentsEnd = false;
        if (this.request) {
            this.request.abort()
        }
        this.fetchComment({
            foodId: this.currentFood.values.id,
            page: this.pageCount
        },
        {
            isMore: false,
            changeCommentType: true,
            commentType: this.commentType
        })
    };
    r.prototype._destroyAll = function() {
        this._destroyComment();
        this.commentData = {};
        this.currentFood = null;
        if (this.currentFoodView) {
            this.currentFoodView.destroy();
            this.currentFoodView = null
        }
        this.$el.empty()
    };
    r.prototype._destroyComment = function() {
        var e;
        this.commentList = [];
        for (e in this.commentViews) {
            this.commentViews[e].destroy();
            delete this.commentViews[e]
        }
    }; ! Eleme.Controller && (Eleme.Controller = {});
    Eleme.Controller.CommentManager = r
})(); (function() {
    "use strict";
    if (typeof Eleme === "undefined") {
        window.Eleme = {}
    }
    var e = Eleme.Common.Evt,
    t = Eleme.Common.PubSub,
    o = Eleme.Common.RenderBuffer;
    var r = Eleme.Model.Food,
    a = Eleme.Model.Restaurant,
    n = Eleme.View.FavorFoodView,
    s = Eleme.View.RecommendFoodView;
    var i = {
        restaurantSelector: "#restaurant",
        restaurantAsideSelector: "#rst_aside",
        restaurantInfoPanelSelector: ".rst_info_panel",
        restaurantInfoHeaderSelector: ".rst_info_header",
        recommendFoodWrapSelector: "#weekly_ranking",
        favorBtnSelector: ".rst_favor_btn",
        unFavorBtnSelector: ".rst_unfavor_btn",
        restaurantDistanceSelector: ".rst_distance",
        restaurantDeliverAmountSelector: ".rst_deliver_amount",
        rstMapDistanceSelector: "#r_d_v",
        recoFoodContainerSelector: "#rec_food",
        favorFoodWrapSelector: "#favor_food",
        mapSelector: ".rst_map",
        headDistanceSelector: ".rst_head_distance",
        asideDistanceSelector: ".rst_aside_distance",
        feedbackModalSelector: "#modal_feedback",
        feedbackInputSelector: "#feedback_input",
        feedbackFormSelector: "#feedback_form",
        feedbackErrorSelector: ".feedback_err_tip",
        cancelFeedbackSelector: ".cancel_feedback",
        submitFeedbackSelector: ".submit_feedback",
        rstHeaderWrapSelector: ".rst_header_con",
        addBtnSelector: ".add_btn",
        asideCmtSelector: ".rst_aside_comment",
        headerCmtSelector: ".rst_header_comment",
        restaurantInfoDoneTopic: "restaurantDone",
        favorFoodInitTopic: "favorFoodInit",
        favorFoodUpdateTopic: "favorFoodUpdate",
        fetchFoodDoneTopic: "fetchFoodDone",
        userInfoDoneTopic: "userInfoDone",
        emptyFavorTip: '<div class="rst-aside-empty empty_favor"><i class="glyph-fav-off glyph-icon"></i>收藏过的美食在这里</div>',
        moreFavorTip: '<p class="rst-aside-more more_favor"><a class="more" href="http://ele.me/profile/favor_food">查看更多收藏</a></p>',
        favorFoodHead: '<h3 class="rst-aside-title">我的收藏</h3>',
        backIcon: '<a class="btn-last-page" href="<%- data.backUrl %>"><i class="glyph-back"></i><br />返回</a>',
        userInfoUrl: window.location.pathname + "/userinfo",
        getUserInfoVerb: "get",
        feedbackUrl: "/feedback/addSuggestion",
        maxFavorFood: 5
    };
    function d() {
        this.$el = null;
        this.restaurant = new a;
        this.favorFoodViews = [];
        this.events = {};
        this.init()
    }
    $.extend(d.prototype, e);
    d.prototype.init = function() {
        this.$el = $(i.restaurantSelector);
        this.listenTo(this.restaurant, "favorStateChange", $.proxy(this.favorStateHandler, this));
        this.subscribeTopic();
        this.bindEvents()
    };
    d.prototype.subscribeTopic = function() {
        t.subscribe(i.restaurantInfoDoneTopic,
        function(e) {
            this.updateRestaurantInfo(e)
        },
        this);
        t.subscribe(i.favorFoodInitTopic,
        function(e) {
            this.initFavorFood(e)
        },
        this);
        t.subscribe(i.fetchFoodDoneTopic,
        function(e) {
            this.renderRecommendFood(e)
        },
        this);
        t.subscribe(i.favorFoodUpdateTopic,
        function(e, t) {
            this.updateFavorFood(e, t)
        },
        this);
        t.subscribe(i.userInfoDoneTopic,
        function(e) {
            if (!e.authenticated) {
                t.cancelSub(i.favorFoodInitTopic);
                t.cancelSub(i.favorFoodUpdateTopic);
                this.$el.find(i.favorFoodWrapSelector).addClass("hide")
            }
            this.addBackIcon(e.place)
        },
        this)
    };
    d.prototype.bindEvents = function() {
        var e = this,
        t = this.$el.find(i.restaurantAsideSelector),
        o = this.$el.find(i.restaurantInfoHeaderSelector);
        o.on("click", i.starSelector,
        function() {
            _gaq.push(["_trackEvent", "restaurant", "restaurantRating", "headerStar"])
        });
        o.on("click", i.subStarSelector,
        function() {
            _gaq.push(["_trackEvent", "restaurant", "restaurantRating", "smallStar"])
        });
        o.on("click", i.headerCmtSelector,
        function() {
            _gaq.push(["_trackEvent", "restaurant", "restaurantComment", "headerDropdown"])
        });
        t.on("click", i.asideCmtSelector,
        function() {
            _gaq.push(["_trackEvent", "restaurant", "restaurantComment", "aside"])
        });
        o.on("click", i.favorBtnSelector,
        function() {
            _gaq.push(["_trackEvent", "restaurant", "favorRestaurant", "headerDropdown"])
        });
        t.on("click", i.favorBtnSelector,
        function() {
            _gaq.push(["_trackEvent", "restaurant", "favorRestaurant", "aside"])
        });
        t.find(i.recoFoodContainerSelector).on("click", i.addBtnSelector,
        function() {
            _gaq.push(["_trackEvent", "restaurant", "addFood", "fromRecommendAside"])
        });
        t.find(i.favorFoodWrapSelector).on("click", i.addBtnSelector,
        function() {
            _gaq.push(["_trackEvent", "restaurant", "addFood", "fromFavorAside"])
        });
        this.$el.on("click", i.favorBtnSelector,
        function() {
            if (ELEME.authed) {
                e.restaurant.favor()
            } else {
                window.location.href = ELEME.formerBaseUrl + "/login"
            }
        });
        this.$el.on("click", i.unFavorBtnSelector,
        function() {
            if (ELEME.authed) {
                e.restaurant.unFavor()
            } else {
                window.location.href = ELEME.formerBaseUrl + "/login"
            }
        });
        $(i.feedbackFormSelector).on("submit", $.proxy(this.addFeedback, this));
        $(i.cancelFeedbackSelector).on("click",
        function() {
            $(i.feedbackErrorSelector).addClass("hide").html("")
        })
    };
    d.prototype.renderRecommendFood = function(e) {
        var t, a, n, d, c = this.$el.find(i.recommendFoodWrapSelector),
        l = _.chain(e).pluck("foods").flatten(true).filter(function(e) {
            return e.sales !== 0 && e.price >= 8
        }).sortBy("sales").reverse().first(5).value();
        var f = new o;
        if (l.length < 5) {
            return
        }
        for (t = 0, a = l.length; t < a; t++) {
            n = new r(l[t]);
            d = new s(n);
            d.render(f)
        }
        c.append(f.buffer);
        f = null;
        this.$el.find(i.recoFoodContainerSelector).removeClass("hide")
    };
    d.prototype.renderFavorFood = function(e) {
        var t, o, r;
        e = e || [];
        for (t = 0, o = e.length; t < o; t++) {
            r = e[t];
            this.updateFavorFood(r, {
                favor: true
            })
        }
    };
    d.prototype.initFavorFood = function(e) {
        e = e || [];
        var t, o, r;
        for (t = 0, o = e.length; t < o; t++) {
            r = new n(e[t]);
            this.favorFoodViews.push(r)
        }
        this.renderFavorFood()
    };
    d.prototype.updateFavorFood = function(e, t) {
        var o, r, a, s = [],
        i = e.values.id;
        if (t.favor) {
            a = new n(e);
            this.favorFoodViews.push(a)
        } else {
            for (o = 0, r = this.favorFoodViews.length; o < r; o++) {
                if (this.favorFoodViews[o].food.values.id !== i) {
                    s.push(this.favorFoodViews[o])
                } else {}
            }
            this.favorFoodViews = s
        }
        this.renderFavorFood()
    };
    d.prototype.renderFavorFood = function() {
        var e = new o("section");
        e.setClass("rst-aside-block").setId("favor_food");
        e.pushOpenTag();
        e.push(i.favorFoodHead);
        if (this.favorFoodViews.length === 0) {
            e.push(i.emptyFavorTip)
        } else {
            this._renderFavorFood(e);
            if (this.favorFoodViews.length > 5) {
                e.push(i.moreFavorTip)
            }
        }
        e.pushCloseTag();
        this.$el.find(i.favorFoodWrapSelector).replaceWith(e.buffer)
    };
    d.prototype._renderFavorFood = function(e) {
        var t, o;
        e.begin("ul");
        e.setClass("rst-aside-menu-list favor_list");
        e.pushOpenTag();
        for (t = 0, o = Math.min(this.favorFoodViews.length, 5); t < o; t++) {
            this.favorFoodViews[t].render(e)
        }
        e.pushCloseTag()
    };
    d.prototype.updateRestaurantInfo = function(e) {
        this.restaurant.values = e;
        if (this.restaurant.values.distance) {
            this.$el.find(i.restaurantDistanceSelector + "," + i.rstMapDistanceSelector).html(this.restaurant.values.distance)
        } else {
            this.$el.find(i.asideDistanceSelector + "," + i.headDistanceSelector).addClass("hide")
        }
        this.$el.find(i.mapSelector).attr("src", ELEME.staticHost + e.mapUrl);
        this.$el.find(i.restaurantDeliverAmountSelector).html(this.restaurant.values.deliverAmount);
        this.$el.find(i.restaurantInfoPanelSelector).show();
        if (this.restaurant.values.favored) {
            this.$el.find(i.unFavorBtnSelector).removeClass("hide");
            this.$el.find(i.favorBtnSelector).addClass("hide")
        } else {
            this.$el.find(i.unFavorBtnSelector).addClass("hide");
            this.$el.find(i.favorBtnSelector).removeClass("hide")
        }
    };
    d.prototype.addBackIcon = function(e) {
        var t, o = _.template(i.backIcon);
        t = !e ? "http://" + ELEME.rootHost: ELEME.isRestaurantPremium ? "http://" + ELEME.rootHost + "/premium/geohash/" + e: "http://" + ELEME.rootHost + "/place/" + e;
        this.$el.find(i.rstHeaderWrapSelector).prepend(o({
            backUrl: t
        }))
    };
    d.prototype.fetch = function() {
        var e, o;
        e = ELEME.baseUrl + i.userInfoUrl;
        o = i.getUserInfoVerb;
        $.ajax({
            type: o,
            url: e,
            cache: false
        }).done(function(e) {
            t.publish(i.restaurantInfoDoneTopic, e)
        }).fail(function(e) {})
    };
    d.prototype.addFeedback = function(e) {
        var t = "http://" + ELEME.mainHost + i.feedbackUrl,
        o = $.trim($(i.feedbackInputSelector).val());
        e.preventDefault();
        if (o === "") {
            $(i.feedbackErrorSelector).html("亲爱的用户，您还没有添加反馈意见").removeClass("hide");
            return
        }
        $(i.submitFeedbackSelector).html("正在提交");
        $.ajax({
            url: t,
            type: "get",
            dataType: "jsonp",
            data: {
                content: o
            }
        }).done(function(e) {
            if (e === "1") {
                $(i.feedbackModalSelector).modal("hide");
                $(i.feedbackInputSelector).val("");
                $(i.feedbackErrorSelector).html("").addClass("hide");
                $(i.submitFeedbackSelector).html("提交")
            }
        }).fail(function(e) {
            $(i.feedbackErrorSelector).html(e.responseJSON.msg).removeClass("hide");
            $(i.submitFeedbackSelector).html("提交")
        })
    };
    d.prototype.favorStateHandler = function() {
        if (this.restaurant.values.favored) {
            this.$el.find(i.unFavorBtnSelector).removeClass("hide");
            this.$el.find(i.favorBtnSelector).addClass("hide")
        } else {
            this.$el.find(i.unFavorBtnSelector).addClass("hide");
            this.$el.find(i.favorBtnSelector).removeClass("hide")
        }
    }; ! Eleme.Controller && (Eleme.Controller = {});
    Eleme.Controller.RestaurantManager = d
})(); (function() {
    "use strict";
    Eleme.View.views = {};
    Eleme.View.uuid = 0;
    var e = new Eleme.Controller.CommentManager;
    var r = new Eleme.Controller.MenuManager;
    var n = new Eleme.Controller.BasketManager;
    var a = new Eleme.Controller.RestaurantManager;
    r.fetch();
    a.fetch();
    n.fetch()
})();